﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daStaticAnalyser
{
    using daSyntaxAnalyser.SyntaxTree;

    public class SyntaxTreeVisitor
    {
        private static SyntaxTreeVisitor instance;

        public static SyntaxTreeVisitor Instance
        {
            get
            {
                if (instance == null)
                    instance = new SyntaxTreeVisitor();
                return instance;
            }
        }

        public event EventHandler<SyntaxTreeArgs> VisitEvent;

        public void Visit(ISyntaxTreeElement Element)
        {
            if (Element == null) return;
            if (VisitEvent != null)
                VisitEvent(this, new SyntaxTreeArgs(Element));
            else return;
            foreach (ISyntaxTreeElement child in Element)
            {
                if (child == null)
                    throw new Exception("Ошибка обработки! Элемент не обнаружен!");
                else Visit(child);
            }
        }
    }
}
